package com.warm.calc.demo.service.parser.impl;

import com.warm.calc.demo.entity.CalcCompleteData;
import com.warm.calc.demo.entity.CalcKeyword;
import com.warm.calc.demo.entity.CalcSourceData;
import com.warm.calc.demo.entity.CalcType;
import com.warm.calc.demo.service.parser.AbstractAttributeParser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 减排 parser
 */
@Component
public class JianPaiParser extends AbstractAttributeParser {

    @Override
    protected boolean validParameter(final CalcSourceData source, final List<CalcKeyword> keywords, List<CalcType> types) {
        return !CollectionUtils.isEmpty(types) && StringUtils.isNotBlank(source.getWentilx());
    }

    @Override
    public void innerParser(final CalcSourceData source, final CalcCompleteData target,
        final List<CalcKeyword> keywords, List<CalcType> types) {
        types.stream().filter(t -> StringUtils.equals(t.getContent(), source.getWentilx()))
            .findFirst()
            .ifPresent(type -> target.setJianPaiType(type.getType()));
    }
}
